package com.sgs.carbon.web;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Arrays;

/**
 * SGS 核心碳计算项目
 *
 * @author Dave Liu
 * @date 2021-09-30
 */
@Slf4j
@SpringBootApplication
@MapperScan("${carbon.info.mapper-scan}")
public class CarbonPlatformWebApplication {

    private static final String PROJECT_NAME = "SGS 碳数字化管理平台";
    private static final String COMMON_STARTER_PACKAGE = "com.sgs.carbon.starter";

    public static void main(String[] args) {
        ConfigurableApplicationContext run = new SpringApplicationBuilder(CarbonPlatformWebApplication.class)
                .web(WebApplicationType.SERVLET)
                .bannerMode(Banner.Mode.CONSOLE)
                .logStartupInfo(true)
                .run(args);
        log.info("=== {} 开始加载 starter 组件 === ", PROJECT_NAME);
        Arrays.stream(run.getBeanDefinitionNames()).filter(item -> item.startsWith(COMMON_STARTER_PACKAGE)).forEach(System.out::println);
        log.info("=== {} 一共加载了 {} 个 Bean ===", PROJECT_NAME, run.getBeanDefinitionCount());
        String[] profile = run.getEnvironment().getActiveProfiles();
        log.info("=== {} 启动成功, 当前启动环境为 {} ===", PROJECT_NAME, profile[0]);
    }

}